home *** CD-ROM | disk | FTP | other *** search
/ Mac Treasure Chest - Best Games 101 / 101.ISO / Role Play / Robot Warriors / Example Robots / Run Away < prev    next >
Encoding:
Text File  |  1991-08-26  |  4.8 KB  |  146 lines  |  [TEXT/RWar]

  1. ; Robot Name:  RunAway
  2. ;
  3. ;  Tries to stay away from other robots by finding the largest gap between
  4. ;  robots that it can dodge through.
  5. ;
  6. ;  An improvement would be to know about walls and try to keep from getting
  7. ;  cornered by dodging into the open to a far corner, even if it means moving
  8. ;  closer to a robot in order to squeeze by it.
  9.  
  10. CPU_SPEED 2
  11. ARMOR 0
  12. FIRE_RATE 0
  13. ENGINE_SIZE 0
  14. RADAR_RANGE 2
  15. CLOAKING 1
  16. FUEL_CAPACITY 1
  17.  
  18.  
  19.  
  20. define kCLOSE_SEARCH_INCREMENT 3
  21. define true 1
  22. define false 0
  23.  
  24. allocate closestRobotDistance
  25. allocate closestRobotAngle
  26. allocate beginGapWithNoRobots
  27. allocate centerOfGapWithNoRobots
  28. allocate largestCurrentGapWithNoRobots
  29. allocate currentGapSize
  30. allocate oldDamage
  31. allocate totalAngleSearched
  32. allocate searchIncrement
  33. allocate endAngle
  34.  
  35.  
  36.     0 to oldDamage
  37.     0 to direction
  38.     0 to cloak
  39.     20 to speed
  40.     TimeInterrupt to time_int_xfer
  41.     1 to time_int_mask
  42.  
  43.  
  44. repeat
  45.     0 to aim
  46.     0 to beginGapWithNoRobots
  47.     0 to largestCurrentGapWithNoRobots
  48.     0 to centerOfGapWithNoRobots
  49.     0 to currentGapSize
  50.     0 to totalAngleSearched
  51.     9999 to closestRobotDistance
  52.      ;Start by finding first robot to begin looking for first gap.
  53.     repeat
  54.         aim to radar
  55.         aim + searchIncrement to aim
  56.     until radar > 0
  57.     aim to endAngle
  58.     radar to closestRobotDistance
  59.     aim to closestRobotAngle
  60.     repeat
  61.         aim + searchIncrement to aim to radar
  62.         if radar > 0 then  ; Found another robot, see if it is the closest one so far.
  63.              if shot = 0 then radar to shot
  64.              if radar < closestRobotDistance then
  65.                   radar to closestRobotDistance
  66.                   aim to closestRobotAngle
  67.               end
  68.                  ;Don't worry about robots over 250 pixels away when looking for gaps.
  69.               if radar < 250 then
  70.                   trace
  71.                   if currentGapSize > largestCurrentGapWithNoRobots then
  72.                          ; A big improvement here would be to disregard gaps that would
  73.                          ; force us too close to a wall.  Right now we can get cornered by
  74.                          ; robots because we run away to the biggest gap which may be towards
  75.                          ; a wall.
  76.                       currentGapSize to largestCurrentGapWithNoRobots
  77.                          ; note the gap and start off in that direction while we search for a bigger gap
  78.                       0 - largestCurrentGapWithNoRobots/2 + aim to centerOfGapWithNoRobots
  79.                       if currentGapSize > 120 then centerOfGapWithNoRobots to direction
  80.                   end
  81.                   0 to currentGapSize
  82.               end
  83.         else  ;Don't see a robot, so the gap grows.
  84.             currentGapSize + searchIncrement to currentGapSize
  85.             totalAngleSearched + searchIncrement to totalAngleSearched
  86.         end
  87.         ;Did a 360 so
  88.         if endAngle-searchIncrement mod 360 < aim then   ; if endAngle - searchIncrement < aim <= endAngle
  89.             if aim <= endAngle then 
  90.                 trace
  91.                 if currentGapSize > largestCurrentGapWithNoRobots then
  92.                        ; A big improvement here would be to disregard gaps that would
  93.                        ; force us too close to a wall.  Right now we can get cornered by
  94.                        ; robots because we run away to the biggest gap which may be towards
  95.                        ; a wall.
  96.                     currentGapSize to largestCurrentGapWithNoRobots
  97.                        ; note the gap and start off in that direction while we search for a bigger gap
  98.                     0 - largestCurrentGapWithNoRobots/2 + aim to centerOfGapWithNoRobots
  99.                     if currentGapSize > 120 then centerOfGapWithNoRobots to direction
  100.                 end
  101.             end
  102.         end
  103.     until totalAngleSearched > 360  ;Search 1 loop then reset variables
  104.     centerOfGapWithNoRobots to direction
  105.     if closestRobotDistance < 150 then
  106.         20 to speed
  107.     else
  108.         10 to speed
  109.     end
  110. until true = false
  111.  
  112.  
  113. define kTURN_RATE 90
  114. define SAFETY_DIST 40
  115.  
  116. AdjustDirection
  117.     if direction < 180 then  ;Check right wall
  118.         if XMAX-SAFETY_DIST < x then direction + kTURN_RATE to direction
  119.     else        ;Check left wall
  120.         if x < SAFETY_DIST then direction + kTURN_RATE to direction
  121.     end
  122.     if direction < 90 then  ;Check top wall
  123.         if y < SAFETY_DIST then direction + kTURN_RATE to direction
  124.     else
  125.         if direction > 270 then  ;Check top wall
  126.             if y < SAFETY_DIST then direction + kTURN_RATE to direction
  127.         else    ; Check bottom wall because  90 < direction < 270
  128.             if YMAX-SAFETY_DIST < y then direction + kTURN_RATE to direction
  129.         end
  130.     end
  131. return
  132.  
  133.  
  134.     
  135.  
  136.  
  137. TimeInterrupt
  138.     num_Robots to searchIncrement
  139.     gosub AdjustDirection
  140.     if cloak > 0 then cloak - 1 to cloak
  141.     if damage <> oldDamage then
  142.         5 to cloak
  143.         damage to oldDamage
  144.     end
  145. endint
  146.